
uniform sampler2D textScreen, textBloom1, textBloom2, textBloom3, textBloom4;
uniform bool useBloom;
uniform int typeBloom;

// Applique les differentes texture de bloom
vec4 addBloom(vec4 baseColor)
{
	vec2 st = gl_TexCoord[0].st;
	float exposure = 1.7;
	float brightMax = 2.0;
	vec4 bloomColor;
	
	if(typeBloom==0)
	{
		bloomColor = texture2D(textBloom1, st) + texture2D(textBloom2, st)*.5 + texture2D(textBloom3, st)*0.25 + texture2D(textBloom4, st)*0.25 ;
	}
	else if(typeBloom==1)
	{
		bloomColor = texture2D(textBloom1, st);
	}
	
	baseColor += bloomColor * 1.0;

	float YD = exposure * (exposure/brightMax + 1.0) / (exposure + 1.0);
	baseColor *= YD;
	return baseColor;
}


void main(void)
{
	vec4 result = texture2D(textScreen, gl_TexCoord[0].st);

	

	// On applique le bloom
	if(useBloom)
	{
		result = addBloom(result);
	}

	gl_FragColor = result;
	
	
}
